package com.dayly.tools;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Pattern;

import okio.BufferedSink;
import okio.BufferedSource;
import okio.Okio;

public class CopyPngOrJpejFile {
    public static void main(String[] args) {
        final ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        String destDir = "F:\\crashFile\\icons";
        final Pattern compile = Pattern.compile("[A-Za-z0-9_]+(.[^9]?.png|.jpg)$");
        String dir = "D:\\develop\\workspace\\trunk\\app\\src\\main\\res\\drawable-xhdpi";
        File dest = new File(dir);
        final File[] files = dest.listFiles();
        for (File icon : files) {
            if (compile.matcher(icon.getName()).matches()) {
                threadPool.execute(() -> copy(icon, new File(destDir, icon.getName())));
            }
        }

    }


    public static void copy(File source, File dest) {
        try (final BufferedSource bufferedSource = Okio.buffer(Okio.source(source)); final BufferedSink bufferedSink = Okio.buffer(Okio.sink(dest))) {
            bufferedSink.writeAll(bufferedSource);
            bufferedSink.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            System.out.println("copy " + source.getName());
        }
    }

}
